package com.untour.im.server.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.untour.im.server.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
public class LoginServiceImpl implements LoginService {
    private static final Map<String,String> userIdMap = new ConcurrentHashMap<>();
    @Override
    public String checkTokenAndGetUserInfo(String token) {
        //todo 后续改成dubbo接口获取用户信息
        String userId = userIdMap.get(token);
        if(!StringUtils.hasText(userId)){
            userId = RandomUtil.randomNumbers(20);
            userIdMap.put(token,userId);
        }
        return userId;
    }
}
